#include <Tictoc.hpp>

Tictoc::Tictoc(){
	Tic();
}

void Tictoc::Tic(){
	GetSystemTime( &begin_time_ );
}

float Tictoc::DiffBetweenTwoTimes(const SYSTEMTIME& begin_time , const  SYSTEMTIME& end_time){
	float difference_time = end_time.wHour -  begin_time.wHour;

	if( difference_time < 0 )
		difference_time += 24;

	difference_time *= 60;

	difference_time += end_time.wMinute - begin_time.wMinute;
	difference_time *= 60;

	difference_time += end_time.wSecond - begin_time.wSecond;

	difference_time += (end_time.wMilliseconds - begin_time.wMilliseconds)/1000.0f;

	return difference_time;
}

float Tictoc::Toc() const {
	SYSTEMTIME end_time_;
	GetSystemTime( &end_time_);

	return DiffBetweenTwoTimes( begin_time_,end_time_);
}

float Tictoc::TocAndTic(){
	float f = Toc();
	Tic();
	return f;
}


float TictocAverage::Toc(){
	float f = Tictoc::Toc();
	intervals_.Insert(f);
	return f;
}


void TictocAverage::Clear(){
	intervals_.Clear();
}


float TictocAverage::AverageToc() const {
	return intervals_.Avg();
}

float TictocAverage::TocAndTic(){
	float f = Toc();
	Tic();
	return f;
}
